Skip to content

feat(tools-performance): Add @rnx-kit/tools-performance package#4079

Merged
JasonVMo merged 12 commits intomainfrom
user/jasonvmo/tools-perf
Apr 13, 2026
Merged

feat(tools-performance): Add @rnx-kit/tools-performance package#4079
JasonVMo merged 12 commits intomainfrom
user/jasonvmo/tools-perf

Conversation

@JasonVMo
Copy link
Copy Markdown
Collaborator

@JasonVMo JasonVMo commented Apr 9, 2026

Description

This adds a framework for doing lightweight performance tracing, some basic reporting, and enabling tracing at a global level.

Usage

In packages, to add instrumentation:

import { getTrace } from "@rnx-kit/tools-performance";

async function myFunction() {
  // will return a logging tracer if "transform" is enabled, a passthrough if not
  const trace = getTrace("transform");
  // trace a sync closure
  const result1 = trace("func1", () => doSomething(p1, p2));
  // trace a sync function without creating a closure
  const result2 = trace("process result, doSomethingElse, result1, options);
  // trace an async function and return
  const final = await trace("call async", finalCall, result2);
  return final;
}

Right now, to enable this for metro bundling a user would add in their metro.config.js:

import { trackPerformance } from "@rnx-kit/tools-performance";

// these would all work
trackPerformance("transform"); // only turn on this one area
trackPerformance(["transform", "metro"]); // turn on a set of areas
trackPerformance(/* or true */); // turn on all performance tracing

Future things to add (or consider)

  • instrument various parts of our infrastructure
  • add an implementation of unstable_perfLoggerFactory that hooks into this
  • have our metro config automatically add the unstable_perfLoggerFactory if "metro" is enabled
  • consider adding a cli option that will enable perf logging for our tools automatically

Other notes

  • text is styled using the formatting from node:utils
  • simple table formatting in the same format as console.table is added, except with support for formatted text.

Copy link
Copy Markdown
Member

@tido64 tido64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly minor issues/nits

Co-authored-by: Tommy Nguyen <4123478+tido64@users.noreply.github.com>
@JasonVMo JasonVMo enabled auto-merge (squash) April 13, 2026 16:52
@JasonVMo JasonVMo merged commit 7811f22 into main Apr 13, 2026
15 checks passed
@JasonVMo JasonVMo deleted the user/jasonvmo/tools-perf branch April 13, 2026 17:18
@JasonVMo JasonVMo restored the user/jasonvmo/tools-perf branch April 13, 2026 17:35
@JasonVMo JasonVMo deleted the user/jasonvmo/tools-perf branch April 13, 2026 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants